var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var UI_EquipInfo_UIBindings = require("AA_UI_EquipInfo_UIBindings");
var UIView = require("AA_UIView");
var Excel = require("AA_Excel");
var BundleConfig = require("AA_BundleConfig");
var Item_Bag_EquipItem = require("AA_Item_Bag_EquipItem");
var PlayerDataManager = require("AA_PlayerDataManager");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var Item_Bag_CiTiao = require("AA_Item_Bag_CiTiao");
var TipsManager = require("AA_TipsManager");
var CommonUtils = require("AA_CommonUtils");
var AudioManager = require("AA_AudioManager");
var Const_Common = require("AA_Const_Common");
var GuideControl = require("AA_GuideControl");
var Const_Game = require("AA_Const_Game");
var RedPointControl = require("AA_RedPointControl");
var AIControl = require("AA_AIControl");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_EquipInfo = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    this.args = e;
    this.StartSet();
  };
  _creator.prototype.onEnable = function () {
    var e = this;
    this.scheduleOnce(function () {
      if (PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.仓库升级) == Const_Common.UpEquipLevelGuideIndex.引导点击升级3) {
        var t = e;
        var o = t.auto_ui.btn_upLevelBtn.node;
        var n = o.convertToWorldSpaceAR(cc.v2(0, 0));
        var i = cc.size(o.width, o.height);
        GuideControl.GuideCtrl.ShowGuide({
          callBack: function () {
            t.ClickUpLevel();
            PlayerDataManager.PlayerDataMgr.SetGuideIndex(Const_Common.GuideName.仓库升级, Const_Common.UpEquipLevelGuideIndex.引导战斗4);
            GuideControl.GuideCtrl.ShowGuide({
              callBack: function () {
                PlayerDataManager.PlayerDataMgr.SetGuideIndex(Const_Common.GuideName.仓库升级, Const_Common.UpEquipLevelGuideIndex.引导完结);
                HallGlobalVariable.default.selfMap["仓库引导升级完"] = 1;
                if (HallGlobalVariable.default.selfMap["战斗按钮"]) {
                  GuideControl.GuideCtrl.ShowOneShou({
                    parent: HallGlobalVariable.default.selfMap["战斗按钮"],
                    isWillClickClose: true,
                    x: 0,
                    y: 0,
                    getFingerCallBack: null
                  });
                  e._close();
                }
              },
              sayStr: "继续挑战关卡，可解锁更强大的水果并获得大量奖励"
            });
          },
          sayStr: "水果升级会增加基础属性，达到特定等级会解锁新的技能",
          wPos: n,
          size: i
        });
      } else if (PlayerDataManager.PlayerDataMgr.GetGuideIndexByTaskName(Const_Common.GuideName.水果上阵) == Const_Common.DressUpEquipGuideIndex.引导穿戴) {
        PlayerDataManager.PlayerDataMgr.SetGuideIndex(Const_Common.GuideName.水果上阵, Const_Common.DressUpEquipGuideIndex.引导完结);
        GuideControl.GuideCtrl.ShowOneShou({
          parent: e.auto_ui.btn_useBtn.node,
          isWillClickClose: true,
          x: 0,
          y: 0,
          getFingerCallBack: null
        });
      } else {
        e.AICheck();
      }
    }, .5);
  };
  _creator.prototype.onDisable = function () {
    1 != HallGlobalVariable.default.selfMap["仓库引导升级完"] && EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HideGuideShow);
  };
  _creator.prototype.StartSet = function () {
    var e = Excel.Excel.shuiguo(this.args.openData.shuiGuoId);
    var t = PlayerDataManager.PlayerDataMgr.GetEquipDataById(this.args.openData.shuiGuoId);
    this.auto_ui.txt_nameLabel.string = e.name;
    this.auto_ui.txt_decLabel.string = e.shuiguomiaoshu;
    this.ShowCard();
    this.ShowCiTiao();
    this.GetAttribute();
    this.auto_ui.sp_tianFuIcon.spriteFrame = null;
    e.id != Const_Game.FruitId.杨桃忍者 && this.LoadSprite(e.id);
    this.auto_ui.txt_unLockLabel.string = t.isUnLock ? "" : "通过章节" + e.unLock + "解锁";
    var o = PlayerDataManager.PlayerDataMgr.HallGetEquipIsDressUp(this.args.openData.shuiGuoId);
    this.auto_ui.btn_clearBtn.node.active = o;
    this.auto_ui.btn_upLevelBtn.node.active = t.isUnLock && t.level <= this.args.openData.upLevelDatas.length;
    this.auto_ui.btn_useBtn.node.active = t.isUnLock && !o;
    if (t.level > this.args.openData.upLevelDatas.length) {
      this.auto_ui.txt_upPriceLabel.string = "MAX";
    } else {
      this.needData = this.args.openData.upLevelDatas[t.level - 1];
      this.auto_ui.txt_upPriceLabel.string = this.needData.money + "";
    }
  };
  _creator.prototype.GetAttribute = function () {
    var e = this;
    var t = ["最前", "随机", "轮流", "精英", "-", "随机", "最前", "-", "-", "最前"];
    var o = Excel.Excel.shuiguo(this.args.openData.shuiGuoId);
    var n = HallGlobalVariable.default.GetShuiGuoCurrLevelData(this.args.openData.shuiGuoId);
    this.auto_ui.node_attributeFather.children.forEach(function (i, a) {
      var r = i.getChildByName("value").getChildByName("valueLabel").getComponent(cc.Label);
      var c = i.getChildByName("value").getChildByName("addLabel").getComponent(cc.Label);
      c.string = "";
      r.string = "-";
      switch (a) {
        case 0:
          if (0 != o.attack && e.args.openData.shuiGuoId != Const_Game.FruitId.辣妹子) {
            r.string = "" + n[0].atk;
            n[1].atk > n[0].atk && (c.string = "+" + (n[1].atk - n[0].atk));
          }
          break;
        case 1:
          if (0 != o.attackspeed) {
            r.string = "" + n[0].atkSpeed;
            n[1].atkSpeed > n[0].atkSpeed && (c.string = "+" + (n[1].atkSpeed - n[0].atkSpeed));
          }
          break;
        case 2:
          r.string = t[o.attackstate - 1];
          break;
        case 3:
          var s = false;
          o.littleDesc && o.littleDesc.length > 0 && (s = true);
          i.getChildByName("nameLabel").getComponent(cc.Label).string = s ? o.littleDesc : "-";
          if (o.id == Const_Game.FruitId.紫薯精) {
            r.string = Excel.Excel.shuiguobuff(o.talent).probability + "%";
          } else if (s && n[0] && n[0].talent[0]) {
            var u = n[0].buffIsBaiFenBi ? "%" : "";
            if (o.id == Const_Game.FruitId.榴莲王) {
              r.string = Excel.Excel.shuiguobuff(o.talent).probability + u;
            } else if (o.id == Const_Game.FruitId.香蕉射手) {
              r.string = n[0].talent[1] + u;
            } else {
              r.string = n[0].talent[0] + u;
            }
            if (n[1].talent[0] > n[0].talent[0]) {
              var l = n[1].talent[0] - n[0].talent[0];
              if (-1 != (l + "").indexOf(".")) {
                c.string = "+" + l.toFixed(1);
              } else {
                c.string = "+" + l;
              }
            }
          }
      }
    });
  };
  _creator.prototype._clickListener = function (e) {
    switch (e) {
      case this.auto_ui.btn_upLevelBtn:
        this.ClickUpLevel();
        break;
      case this.auto_ui.btn_clearBtn:
        EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HallBagRemoveId, this.args.openData.shuiGuoId);
        this._close();
        break;
      case this.auto_ui.btn_useBtn:
        if (PlayerDataManager.PlayerDataMgr.dressUpArray.filter(function (e) {
          return 0 == e;
        }).length <= 0) {
          EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HallBagShowDrag, this.args.openData.shuiGuoId);
        } else {
          PlayerDataManager.PlayerDataMgr.AddDressUpEquip(this.args.openData.shuiGuoId);
          EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HallResetBag);
        }
        this._close();
        break;
      case this.auto_ui.btn_closeBtn:
        this._close();
    }
  };
  _creator.prototype.ClickUpLevel = function () {
    if (PlayerDataManager.PlayerDataMgr.globalData.gold < this.needData.money) {
      TipsManager.TipMgr.showToast("金币不足");
    } else if (PlayerDataManager.PlayerDataMgr.UseEquipFragments(this.args.openData.shuiGuoId, this.needData.shengjixiaohao)) {
      PlayerDataManager.PlayerDataMgr.SubGold(this.needData.money);
      PlayerDataManager.PlayerDataMgr.AddEquipLevel(this.args.openData.shuiGuoId);
      this.StartSet();
      this.args.upLevelReset && this.args.upLevelReset();
      AudioManager.AudioMgr.playEffect("audio/effect/upLevel");
      this.auto_ui.node_upLevelEffect.active = true;
      this.auto_ui.node_upLevelEffect.children.forEach(function (e) {
        e.getComponent(cc.ParticleSystem).resetSystem();
      });
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.upEquip);
    }
  };
  _creator.prototype.ShowCard = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      return __generator(this, function (o) {
        switch (o.label) {
          case 0:
            if (this.cardItemComp) {
              return [3, 2];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Home, "home/" + "item/Item_bag_equipItem", cc.Prefab)];
            }
          case 1:
            e = o.sent();
            (t = cc.instantiate(e)).parent = this.auto_ui.node_cardFather;
            t.setPosition(0, 0);
            this.cardItemComp = t.getComponent(Item_Bag_EquipItem.default);
            o.label = 2;
          case 2:
            this.cardItemComp.StartSet(this.args.openData, false, false);
            this.cardItemComp.auto_ui.txt_nameLabel.string = "";
            return [2];
        }
      });
    });
  };
  _creator.prototype.ShowCiTiao = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t = this;
      return __generator(this, function (o) {
        switch (o.label) {
          case 0:
            if (this.ciTiaoPfb) {
              return [3, 2];
            } else {
              e = this;
              return [4, this._loadRes(BundleConfig.BundleNames.Home, "home/" + "item/item_bag_ciTiao", cc.Prefab)];
            }
          case 1:
            e.ciTiaoPfb = o.sent();
            o.label = 2;
          case 2:
            this.scheduleOnce(function () {
              var e = HallGlobalVariable.default.shuiGuoCiTiaoMap.get(t.args.openData.shuiGuoId);
              e.sort(function (e, t) {
                return e.jiesuo - t.jiesuo;
              });
              t.auto_ui.node_ciTiaoFather.children.forEach(function (e) {
                return e.active = false;
              });
              for (var o = 0; o < e.length; o++) {
                var n = e[o];
                var i = undefined;
                if (o < t.auto_ui.node_ciTiaoFather.childrenCount) {
                  i = t.auto_ui.node_ciTiaoFather.children[o];
                } else {
                  (i = cc.instantiate(t.ciTiaoPfb)).parent = t.auto_ui.node_ciTiaoFather;
                }
                i.active = true;
                i.getComponent(Item_Bag_CiTiao.default).StartSet(n);
              }
            });
            return [2];
        }
      });
    });
  };
  _creator.prototype.LoadSprite = function (e) {
    return __awaiter(this, undefined, undefined, function () {
      var t = this;
      return __generator(this, function () {
        this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/tianfuicon/tianfu_" + e, cc.SpriteFrame).then(function (e) {
          t.auto_ui.sp_tianFuIcon.spriteFrame = e;
          CommonUtils.default.LimitSpriteMaxSize(t.auto_ui.sp_tianFuIcon, 80);
        });
        return [2];
      });
    });
  };
  _creator.prototype.AICheck = function () {
    var e = this;
    if (AIControl.default._instance.isOpen) {
      var t = this;
      if (PlayerDataManager.PlayerDataMgr.globalData.gold >= this.needData.money && PlayerDataManager.PlayerDataMgr.GetEquipDataById(this.args.openData.shuiGuoId).fragments >= this.needData.shengjixiaohao) {
        AIControl.default._instance.ShowClickBtn(this.auto_ui.btn_upLevelBtn.node, function () {
          t.ClickUpLevel();
          t.AICheck();
        });
      } else {
        this.args.isAiDressUp && AIControl.default._instance.ShowClickBtn(this.auto_ui.btn_useBtn.node, function () {
          if (PlayerDataManager.PlayerDataMgr.dressUpArray.filter(function (e) {
            return 0 == e;
          }).length <= 0) {
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HallBagShowDrag, e.args.openData.shuiGuoId);
          } else {
            PlayerDataManager.PlayerDataMgr.AddDressUpEquip(e.args.openData.shuiGuoId);
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.HallResetBag);
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.ResetWareHouseAI);
          }
          e._close();
        });
      }
    }
  };
  __decorate([_property(UI_EquipInfo_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  return __decorate([_ccclass], _creator);
}(UIView.default);
exports.default = _def_UI_EquipInfo;